package StudyCode.summary.zipfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ZipFile {
	public static void zipFile(File inputFile, File outputZip) {
		byte[] buffer = new byte[1024];

		try {
			FileOutputStream fos = new FileOutputStream(outputZip);
			ZipOutputStream zos = new ZipOutputStream(fos);
			ZipEntry ze = new ZipEntry(inputFile.getName());
			zos.putNextEntry(ze);
			FileInputStream in = new FileInputStream(inputFile);

			int len;
			while ((len = in.read(buffer)) > 0) {
				zos.write(buffer, 0, len);
			}

			in.close();
			zos.closeEntry();

			zos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
